package com.shen.educms.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shen.commonutils.Result;
import com.shen.educms.entity.CrmBanner;
import com.shen.educms.service.CrmBannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 首页banner表 前端控制器
 * </p>
 *
 * @author shenkaituo
 * @since 2020-06-30
 */
@RestController
@CrossOrigin
@RequestMapping("/educms/crmbanneradmin")
public class BannerAdminController {
    @Autowired
    CrmBannerService crmBannerService;
    @GetMapping("pageBanner/{page}/{limit}")
    public Result pageBanner(@PathVariable long page,@PathVariable long limit){
        Page<CrmBanner> pageBanner=new Page<>(page,limit);
        crmBannerService.page(pageBanner,null);
        return  Result.ok().data("items",pageBanner.getRecords()).data("total",pageBanner.getTotal());
    }
    @PostMapping("addBanner")
    public  Result addBanner(@RequestBody CrmBanner banner){
        crmBannerService.save(banner);
        return Result.ok();
    }
    @PutMapping("update")
    public Result updateById(@RequestBody CrmBanner banner){
        crmBannerService.updateById(banner);
        return  Result.ok();
    }

    @DeleteMapping("remove/{id}")
    public Result remove(@PathVariable long id){
        crmBannerService.removeById(id);
        return  Result.ok();

    }

    @GetMapping("get/{id}")

    public Result get(@PathVariable String id) {
        CrmBanner banner = crmBannerService.getById(id);

        return Result.ok().data("item", banner);
    }
}

